#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

multimap<int, int> p1;
multimap<int, int>::iterator p;
int t, lis[100860];

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        p1.insert(pair<int, int>(t, i));
    }
    for (int i = 0; i <= n + 1; i++)
    {
        lis[i] = 666666;   
    }
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        p = p1.find(t);
        if (p != p1.end())
        {
            int *ip = lower_bound(lis, lis + n + 1, p->second);
            *ip = p->second; 
        }
    }
    int k;
    for (k = 0; lis[k] != 666666; k++);
    cout << k;
    
    return 0;
}
